package com.stu.test;

import com.stu.common.utils.DataInsertUtil;
import com.stu.entity.Class;
import com.stu.entity.Student;
import com.stu.mapper.ClassMapper;
import com.stu.mapper.StudentMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

@SpringBootTest

public class demo {

    @Autowired
    StudentMapper studentMapper;

    @Autowired
    ClassMapper classMapper;

    @Test
    public void test() {
        Student student=new Student();
        Random random = new Random();
        String[] name = new String[]{"男", "女"};
        int sno=10001;

        List<Class> classList = classMapper.selectList(null);

        for (int i = 0; i < 3200; i++) {

            Map<String, String> generateName = DataInsertUtil.GenerateName();
            Map<String, Object> generateUid = DataInsertUtil.GenerateUid();
            Class getclass = classList.get((int) (Math.random() * 32));
            Integer cno = getclass.getCno();
            Integer tno = getclass.getTno();
            Integer mno = getclass.getMno();

            student.setId(i);
            student.setSno(sno);
            student.setPassWord(String.valueOf(sno));
            if (name[(int) (Math.random() * 2)].equals("男")) {
                student.setName(generateName.get("son"));
                student.setSex("男");
            } else {
                student.setName(generateName.get("daughter"));
                student.setSex("女");
            }
            student.setUid(String.valueOf(generateUid.get("uid")));
            student.setAge((Integer) generateUid.get("age"));
            student.setBirth((LocalDateTime) generateUid.get("birth"));
            student.setPnum(DataInsertUtil.GeneratePhone());
            student.setStime((LocalDateTime) generateUid.get("stime"));
            student.setFname(generateName.get("father"));
            student.setFpnum(DataInsertUtil.GeneratePhone());
            student.setMname(generateName.get("mother"));
            student.setMpnum(DataInsertUtil.GeneratePhone());
            student.setAddress(DataInsertUtil.GenerateAddress());
            student.setCno(cno);
            student.setTno(tno);
            student.setMno(mno);
            student.setCreateUser("admin");
            sno++;

            studentMapper.insert(student);
        }

    }


    @Test
    public void demo2() {
        List<Student> stuList = studentMapper.getStuList();
        System.out.println(stuList);
    }

}
